/**************************************************************************************
 *
 * @(#) SecurityUtils.java
 * @Package com.jgdt.jgdtkasannong_university_gene_backend.utils
 **************************************************************************************/
package com.jgdt.jgdtkasannong_university_gene_backend.utils;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtils {

    /***
     * 获取当前登录用户名
     * @return
     */
    public static String getCurrentUsername() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null || !authentication.isAuthenticated()) {
            return null;
        }
        return ((UserDetails) authentication.getPrincipal()).getUsername();
    }
}




